import java.util.Random;


public class VirtualMachine {
	
	String Name;
	
	double CPU;
	double Mem;
	double BW;
	
	double CPUUsage;
	double MemUsage;
	double BWUsage;
	
	Server PhysicalServer;
	
	boolean blocked = false;
	
	Random rndm;
	
	public VirtualMachine(String name, double cpu, double mem, double bw){
		
		this.Name = name;
		this.CPU = cpu;
		this.Mem = mem;
		this.BW = bw;
		
		this.blocked = false;
		
		this.rndm = new Random();
		
		randomizeUsage();
		
	}
	
	public void setPhysicalServer(Server s){
		
		if(this.PhysicalServer != null && this.PhysicalServer != s && this.PhysicalServer.VMs.contains(this))
			this.PhysicalServer.VMs.remove(this);
		
		this.PhysicalServer = s;
		
	}
	
	public void randomizeUsage(){
		
		CPUUsage = -1.0;
		while(CPUUsage < 0 || CPUUsage > CPU)
			CPUUsage = (rndm.nextGaussian() + 1) * CPU/2;
		
		MemUsage = -1.0;
		while(MemUsage < 0 || MemUsage > Mem)
			MemUsage = (rndm.nextGaussian() + 1) * Mem/2;
		
		BWUsage = -1.0;
		while(BWUsage < 0 || BWUsage > BW)
			BWUsage = (rndm.nextGaussian() + 1) * BW/2;
		
		// the following three lines will not be included in the submitted code. i left them here so that the testing results would be understandable.
		CPUUsage = CPU;
		MemUsage = Mem;
		BWUsage = BW;
		
	}

	public double getCPUUsage() {
		
		return(CPUUsage);
		
	}

	public double getMemUsage() {
		
		return(MemUsage);
		
	}

	public double getBWUsage() {
		
		return(BWUsage);
		
	}
	
	
	
	
	public String toString(){
		
		String result = "VM Name: "+Name+" , CPU: "+CPU+"GHz , Mem: "+Mem+"GB , BW: "+BW+"Mbps";
		
		return(result);
		
	}

}
